package com.xinchuang.mapper.targetSystem;

import com.xinchuang.entity.targetSystem.WeaponData;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @ClassName WeaponMapper
 * @Description: TODO(武器库操作)
 * @Author zhangxuan
 * @Date 2022-03-03 11:03
 * @Verion V1.0
 */
public interface WeaponMapper {

    @Insert(value = {
            "INSERT INTO weapon_table (id,weapon_name,remark,create_time) ",
            "VALUES ",
            "(#{id},#{weaponName},#{remark},CURRENT_TIMESTAMP)",
            "ON DUPLICATE KEY UPDATE weapon_name = #{weaponName},remark = #{remark}"
    })
    int addWeaponAndId(WeaponData weaponData);

    @Delete(value = "DELETE FROM weapon_table WHERE id = #{id}")
    int deleteWeapon(@Param("id") String id);

    @Select(value = "SELECT id,weapon_name,remark FROM weapon_table ORDER BY create_time DESC")
    @Results(value = {
            @Result(property = "weaponName", column = "weapon_name")
    }, id = "weaponMapperName")
    List<WeaponData> selectWeaponList();

    @Select(value = "SELECT id,weapon_name,remark FROM weapon_table WHERE id = #{id} LIMIT 1")
    @ResultMap(value = "weaponMapperName")
    WeaponData selectWeaponOnly(@Param("id") String id);

    @Select(value = "SELECT weapon_name FROM weapon_table WHERE id = #{id} LIMIT 1")
    String selectWeaponName(@Param("id") String id);

    @Select(value = "SELECT id FROM weapon_table WHERE weapon_name = #{name} LIMIT 1")
    String selectWeaponNameByName(@Param("name") String name);

}